package com.csair.seam.domain.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csair.seam.domain.mapper.IdleReceiveMapper;
import com.csair.seam.domain.mapper.IdleShowMapper;
import com.csair.seam.domain.model.entity.IdleShow;
import com.csair.seam.domain.service.IEquipOrgService;
import com.csair.seam.domain.service.IEquipService;
import com.csair.seam.domain.service.IdleShowService;
import com.csair.seam.infrastructure.utils.IdUtils;
import com.csair.seam.infrastructure.web.BaseResponse;
import com.csair.seam.infrastructure.web.ResponseCode;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;
import java.util.regex.Pattern;

@Service
public class IdleShowServiceImpl  extends ServiceImpl<IdleShowMapper,IdleShow> implements IdleShowService{

    @Autowired
    private IdleShowMapper idleShowMapper;

    private IdleReceiveMapper idleReceiveMapper;

    @Autowired
    private IEquipService equipService;

    @Autowired
    private IEquipOrgService iEquipOrgService;

    @Transactional(propagation = Propagation.REQUIRED)
    @DS("aip")
    @Override
    public Integer inserIdleShow(IdleShow idleShow) {
        return idleShowMapper.insert(idleShow);
    }

    @DS("aip")
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Integer inserIdleShow(List<IdleShow> iss) {
        return  saveBatch(iss) ? iss.size() : -1;
    }

    @DS("aip")
    @Override
    public List<IdleShow> getAllcorpAndOrgCode() {
        return idleShowMapper.getAllcorpAndOrgCode();
    }

    @DS("aip")
    @Override
    public boolean validEquipCode(String equipCode) {
        QueryWrapper<IdleShow> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(equipCode),"equip_codes",equipCode);
        if(getBaseMapper().selectCount(queryWrapper) > 0){
            return true;
        }
        return false;
    }
    @DS("aip")
    @Override
    public Integer getMaxShowId() {
        return idleShowMapper.getMaxShowId()==null?0:idleShowMapper.getMaxShowId();
    }

    @DS("aip")
    @Override
    public List<IdleShow> findIdleShow(IdleShow idleShow) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.isNotEmpty(idleShow.getCorpName()),"corpName",idleShow.getCorpName())
                    .eq(StringUtils.isNotEmpty(idleShow.getEquipName()),"corpName",idleShow.getCorpName());
                    //.eq()
        List<IdleShow> iss = getBaseMapper().selectList(queryWrapper);
        return null;
    }

}